using System.ComponentModel.DataAnnotations;
using System.Data.Entity.ModelConfiguration;

namespace WeberTimeTracker.Models.Mapping
{
    public class ClientMap : EntityTypeConfiguration<Client>
    {
        public ClientMap()
        {
            // Primary Key
            this.HasKey(t => t.Client_ID);

            // Properties
            this.Property(t => t.Name)
                .IsRequired()
                .HasMaxLength(50);

            // Table & Column Mappings
            this.ToTable("Clients");
            this.Property(t => t.Client_ID).HasColumnName("Client_ID");
            this.Property(t => t.Address_ID).HasColumnName("Address_ID");
            this.Property(t => t.Name).HasColumnName("Name");

            // Relationships
            this.HasRequired(t => t.Address)
                .WithMany(t => t.Clients)
                .HasForeignKey(d => d.Address_ID);

        }
    }
}
